#! /usr/bin/python
# -*- coding:utf-8 -*-

## ========================================================================
## Copyright (C) 2007-2013  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## ========================================================================

from naviguation import *
from page import *
from config import *
from session import *
from comics import *
import cgi
import os

## DEBUG MODE
import sys
##
sys.stderr = sys.stdout
##

print u"Content-Type: text/html"

## GET HEADER DOCUMENT

print """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" >
  <head>
"""

## GET HEAD CONTENT
cfg=CFG()
config_id=cfg.readValue(u'config')
tag=Head()
meta=tag.getHeadTags(config_id)
print meta
list_tag=tag.getConfig()

## GET HEADER PAGE

print """    
  </head>
  <body>
    <div id="page">
    <br>
    <table border="0" cellspacing="0" cellpadding="0" align="center" width="98%">
      <tr>
	<td class="border_top_left"></td>
	<td class="border_top_center"></td>
	<td class="border_top_right"></td>
      </tr>
        <td class="border_side_left"></td>
	<td>
    <table border="0" cellspacing="0" cellpadding="0" class="page_body">
      <tr>
	<td class="header_logo">
"""

print """    
	  <div id="header_txt">
            <h2>%s</h2><br/>
            <h3>%s</h3><br/>
            <div id='header_alert'></div>
	  </div>
	</td>
      </tr>
      <tr>
	<td class="header_nav">
          <div id="nav">
	  <ul>
""" % (list_tag[u'title'], list_tag[u'pub'])

## GET NAVIGUATION MENU

nav=Nav()
menu=nav.getMenu()
print menu

## GET PAGE TOP

print """
	  </ul>
          </div>
	</td>
      </tr>
      <tr>
	<td class="content">
          <div id="page_content">
"""

## GET PAGE CONTENT

pg=Page()
print pg.getContent(nav.getDefaultPageID())

## GET PAGE BOTTOM

print """
	  </div>
        </td>
      </tr>
      <tr>
	<td class="footer">
	  <div id="footer">
	    %s
	    <br><a class="footer" href="javascript:login();">Login</a>
	  </div>
	</td>
      </tr>
    </table>          
        </td>
        <td class="border_side_right"></td>
      <tr>
	<td class="border_bottom_left"></td>
	<td class="border_bottom_center"></td>
	<td class="border_bottom_right"></td>
      </tr>
    </table>
""" % list_tag[u'name']

# GET SESSION NUMBER

ses=Session()
ses_num=ses.new(cgi.escape(os.environ[u"REMOTE_ADDR"]))

print u"<input type='hidden' id='session' value='%s' />" % ses_num

# GET FOOTER PAGE

print """
    </div>
  </body>
</html>
"""
